home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Startup Screen Picker 1.2 / source / ssp startup app ƒ / Shell ƒ / dialogs.c next >
Encoding:
Text File  |  1994-10-30  |  4.5 KB  |  107 lines  |  [TEXT/KAHL]

  1. are Foundation; either version 2 of the License, or
  2. (at your option) any later version.
  3.  
  4. This program is distributed in the hope that it will be useful,
  5. but WITHOUT ANY WARRANTY; without even the implied warranty of
  6. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  7. GNU General Public License for more details.
  8.  
  9. You should have received a copy of the GNU General Public License
  10. along with this program in a file named "GNU General Public License".
  11. If not, write to the Free Software Foundation, 675 Mass Ave,
  12. Cambridge, MA 02139, USA.
  13.  
  14. \**********************************************************************/
  15.  
  16. #include "dialogs.h"
  17.  
  18. void PositionDialog(ResType theType, short theID)
  19. /* call this function BEFORE loading an alert or dialog box; this function will
  20.    load the alert/dialog into memory and position it centered horizontally and
  21.    positioned 1:3 vertically.  Then, load the alert/dialog right after the call
  22.    to PositionDialog, and the alert/dialog will be loaded from the copy in
  23.    memory, which has already been positioned correctly.  Cute, eh?  See error.c
  24.    for an example. */
  25. {
  26.     Handle                theTemplate;    /* Handle to resource template    */
  27.     register Rect        *theRect;        /* Bounding box of dialog        */
  28.     register short        left;            /* Left side of centered rect    */
  29.     register short        top;            /* Top side of centered rect    */
  30.     
  31.     /* The first field of the resource template for DLOG's and ALRT's */
  32.     /* is its bounding box.  Get a pointer to this rectangle.  This   */
  33.     /* handle dereferencing is safe since the remaining statements in */
  34.     /* this function do not move memory (assignment and simple math). */
  35.  
  36.     theTemplate = GetResource(theType, theID);
  37.     if (theTemplate == 0)
  38.         return;
  39.     theRect=(Rect*)*theTemplate;    /* bounding rectangle */
  40.     
  41.     left = (screenBits.bounds.right - (theRect->right - theRect->left)) / 2;
  42.     top = (screenBits.bounds.bottom - (theRect->bottom - theRect->top)) / 3;
  43.     if (top < (GetMBarHeight() + 1))    /* don't put it over menu bar */
  44.         top = GetMBarHeight() + 1;
  45.  
  46.     theRect->right += left - theRect->left;
  47.     theRect->left = left;
  48.     theRect->bottom += top - theRect->top;
  49.     theRect->top = top;
  50. }
  51.  
  52. pascal void OutlineDefaultButton(DialogPtr myDlog, short itemNum)
  53. /* Use this as the useritem for a dialog which needs an outlined default button. */
  54. /* Make sure the default button is item 1 in the DITL. */
  55. {
  56.     short            itemType;
  57.     Handle            itemH;
  58.     Rect            box;
  59.     
  60.     GetDItem(myDlog, 1, &itemType, &itemH, &box);
  61.     PenSize(3, 3);
  62.     InsetRect(&box, -4, -4);
  63.     FrameRoundRect(&box, 16, 16);
  64.     PenNormal();
  65. }
  66.  
  67. pascal Boolean ProcOFilter(DialogPtr theDialog, EventRecord *theEvent, short *theItem)
  68. /* use this as the proc filter when calling ModalDialog -- it maps RETURN and
  69.    ENTER to button 1, and ESCAPE and COMMAND-PERIOD to button 2.  Of course,
  70.    button 1 should be the OK button and button 2 should be the cancel button. */
  71. {
  72.     unsigned char    theChar;
  73.     short            itemType;
  74.     Handle            itemH;
  75.     Rect            box;
  76.     long            dummy;
  77.     
  78.     switch (theEvent->what)    /* examine event record */
  79.     {
  80.         case keyDown:    /* keypress */
  81.         case autoKey:
  82.             theChar=theEvent->message & charCodeMask;    /* get ascii char value */
  83.             if ((theChar==0x0d) || (theChar==0x03))        /* RETURN or ENTER */
  84.             {
  85.                 *theItem=1;        /* as if the user selected item #1 */
  86.                 GetDItem(theDialog, 1, &itemType, &itemH, &box);
  87.                 HiliteControl((ControlHandle)itemH, 1);    /* flash button 1 by highlighting, */
  88.                 Delay(8, &dummy);                        /* waiting 8 ticks, and then */
  89.                 HiliteControl((ControlHandle)itemH, 0);    /* unhighlighting -- believe */
  90.                 return TRUE;                            /* it or not, that's Apple's */
  91.             }                                            /* preferred method */
  92.             if ((theChar==0x1b) ||    /* ESCAPE */
  93.                 ((theEvent->modifiers & cmdKey) && (theChar=='.')))    /* COMMAND-PERIOD */
  94.             {
  95.                 *theItem=2;        /* as if the user selected item #2 */
  96.                 GetDItem(theDialog, 2, &itemType, &itemH, &box);    /* same as above */
  97.                 HiliteControl((ControlHandle)itemH, 1);
  98.                 Delay(8, &dummy);
  99.                 HiliteControl((ControlHandle)itemH, 0);
  100.                 return TRUE;
  101.             }
  102.             break;
  103.     }
  104.     
  105.     return FALSE;    /* no faking, proceed as planned */
  106. }
  107.